﻿using System;
using WMPLib;

namespace Core
{


    //This could be used to replace irrKlang in Voize. At least partially.
    public class VoizeCorePlayer
    {
        internal VoizeCorePlayer(ICorePlayerEvents core_events)
        {
            m_Player = new WindowsMediaPlayer();
            m_Player.PlayStateChange +=
                         new _WMPOCXEvents_PlayStateChangeEventHandler(core_events.State_Changed);
            m_Player.MediaError +=
                        new WMPLib._WMPOCXEvents_MediaErrorEventHandler(core_events.Error_State);
        }

        private WindowsMediaPlayer m_Player;


        internal void Play(string file)
        {
            m_Player.URL = file;

            if (m_Player.playState == WMPPlayState.wmppsPlaying ||
              m_Player.playState == WMPPlayState.wmppsPaused)
            {
                m_Player.controls.stop();
            }

            m_Player.controls.play();
        }



        internal void PlayUrl(string url)
        {
            m_Player.URL = url;

            if (m_Player.playState == WMPPlayState.wmppsPlaying ||
               m_Player.playState == WMPPlayState.wmppsPaused)
            {
                m_Player.controls.stop();
            }

            m_Player.controls.play();
        }



        internal void Pause()
        {
            if (m_Player.playState == WMPPlayState.wmppsPlaying)
                m_Player.controls.pause();
        }



        internal void Stop()
        {
            if (m_Player.playState == WMPPlayState.wmppsPlaying ||
                m_Player.playState == WMPPlayState.wmppsPaused)
            {
                m_Player.controls.stop();
            }
        }



    }
}
